import axios from 'axios'
axios.defaults.baseURL = 'http://klxin.cn:8888/api/private/v1/'


//导入  加载效果
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'


// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    config.headers.Authorization = window.sessionStorage.getItem('token');
    NProgress.start()
    // console.log(config);
    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    NProgress.done()
    return response;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});

//实现登录
export var login_api = (params) => {
    return axios.post('login', params)
}
//左侧菜单
export var menus_api = () => {
    return axios.get('menus')
}
//用户数据列表
export var users_api = (params1) => {
    return axios.get('users', {
        params: params1
    })
}
//修改用户状态
export var userPut_api = (uId, type) => {
    return axios.put(`users/${uId}/state/${type}`)
}
//编辑用户
export var edituserPut_api = (params) => {
    return axios.put(`users/${params.id}`, {
        email: params.email,
        mobile: params.mobile
    })
}
//删除用户
export var deluserPut_api = (uId) => {
    return axios.delete(`users/${uId}`)
}
//添加用户
export var adduser_api = (params) => {
    return axios.post(`users`, params)
}
// 所有权限
export var rights_api = (type) => {
    return axios.get(`rights/${type}`)
}
// 角色列表
export var roles_api = () => {
    return axios.get(`roles`)
}
//角色授权
export var rolesToRights_api = (params) => {
    return axios.post(`roles/${params.roleId}/rights`, {
        rids: params.rids
    })
}
// 13-分配用户角色
export var rolesSet_api = (params) => {
    return axios.put(`users/${params.id}/role`, {
        rid: params.rid
    })
}
// 14-分类数据列表获取  
export var cateList_api = (params) => {
    return axios.get(`categories`, {
        params
    })
}
//添加分类
export var cateAdd_api = (params) => {
    return axios.post(`categories`, params)
}
//参数列表
export var cateParamsList_api = (params1) => {
    return axios.get(`categories/${params1.id}/attributes`, {
        params: {
            sel: params1.sel
        }
    })
}

//删除参数
export var cateParamsDelete_api = (params1) => {
    return axios.delete(`categories/${params1.id}/attributes/${params1.attrid}`)
}

export var cateAtteAdd_api = (params) => {
    return axios.put(`categories/${params.id}/attributes/${params.attrId}`, {
        attrId: params.attrId,
        attr_name: params.attr_name,
        attr_sel: params.attr_sel,
        attr_vals: params.attr_vals
    })
}
//   添加动态参数或者静态属性
export var cateAddParams_api = (params) => {
    return axios.post(`categories/${params.id}/attributes`, {
        attr_name: params.attr_name,
        attr_sel: params.attr_sel,
        attr_vals: params.attr_vals
    })
}
//商品列表数据
export var goodsList_api = (params) => {
    return axios.get(`goods`, {
        params
    })
}
//删除商品
export var delGoods_api = (id) => {
    return axios.delete(`goods/${id}`)
}
//添加商品
export var goodsAdd_api = (params) => {
    return axios.post(`goods`, params)
}
//订单数据列表
export var orders_api = (params) => {
    return axios.get(`orders`, { params })
}
//reports/type/1
export var reports_api = () => {
    return axios.get(`reports/type/1`)
}